﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using System.Xml;
using System.IO;
using DigiLib;

public partial class controls_admin_ContactInfo : Admin_Controls_Base {
    protected void Page_Load(object sender, EventArgs e) {
        base.removeHGC(divMessage);
        if (!IsPostBack)
            loadData();
    }
    protected void btnSubmit_Click(object sender, EventArgs e) {
        try {
            string content = string.Empty;
            if (ckContent.Text != null)
                content = Server.HtmlEncode(ckContent.Text);
            string fname = Server.MapPath(Setting.PathContact);
            XmlTextWriter xw = new XmlTextWriter(fname, null);
            xw.Formatting = Formatting.Indented;
            xw.Indentation = 6;
            xw.WriteStartDocument();
            xw.WriteStartElement("contact");
            xw.WriteStartElement("content");
            xw.WriteString(content);
            xw.WriteEndElement();
            xw.WriteEndElement();
            xw.WriteEndDocument();
            xw.Flush();
            xw.Close();
            divMessage.InnerHtml = MessageBox.Success("Thông Báo", "Cập nhật thành công.");
        } catch (Exception) {
            throw;
        }
        //lbInfo.Text = "Cập nhật thành công!";
    }
    private void loadData() {
        try {
            string fname = Server.MapPath(Setting.PathContact);
            if (!File.Exists(fname)) {
                return;
            }
            XmlDocument doc = new XmlDocument();
            doc.Load(fname);
            XmlNode root = doc.DocumentElement;
            XmlNodeList list = root.ChildNodes;
            ckContent.Text = Server.HtmlDecode(list.Item(0).InnerText);
        } catch (Exception ex) {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi :<br />" + ex.Message);
        }
    }
}
